Page({
  data: {
    dialogVisible: false,
    houseList: [],
  },
  onLoad() {
    this.getHouseList()
  },
  async getHouseList() {
    let houseList = await wx.http.get('/room')
    console.log(houseList)
    this.setData({ houseList })
  },
  swipeClose(ev) {
    this.cellId = ev.mark.id
    const { position, instance } = ev.detail
    if (position === 'right') {
      // 显示 Dialog 对话框
      this.setData({
        dialogVisible: true,
      })
      // swiper-cell 滑块关闭
      instance.close()
    }
  },

  goDetail({ mark }) {
    wx.navigateTo({
      url: '/house_pkg/pages/detail/index?id=' + mark.id,
    })
  },

  addHouse() {
    wx.navigateTo({
      url: '/house_pkg/pages/locate/index',
    })
  },
  // 确认框的关闭
  async dialogClose(event) {
    console.log(event);
    // 不是确定就跳出
    if (event.detail !== "confirm") return
    console.log(this.cellId);
    // 删除逻辑
    await wx.http.delete('/room/' + this.cellId)
    // 列表更新
    this.getHouseList()
  }
})
